package com.mayikt;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.RecursiveAction;

/**
 * @ClassName ForkJoinSms
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class ForkJoinSms extends RecursiveAction {
    /**
     * 存放手机号码
     */
    private List<String> phones;

    private int start;
    private int end;
    // 1000
    private int max = 100;

    public ForkJoinSms(int start, int end) {
        this.start = start;
        this.end = end;
    }

    @Override
    protected void compute() {
        if (end - start < max) {
            System.out.println(Thread.currentThread().getName() + ",start:" + start + ",end:" + end);
        } else {
            int l = (end + start) / 2;
            ForkJoinSms left = new ForkJoinSms(start, l);

            ForkJoinSms rigt = new ForkJoinSms(l + 1, end);
            left.fork();
            rigt.fork();
        }

    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ForkJoinSms forkJoinSms = new ForkJoinSms(1, 1000);
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        forkJoinPool.invoke(forkJoinSms);
        // 1-500 1-250 251-500  1-251   1-125  125-251

    }
}
